package com.speily.current.wait_notify.deathLock;

/**
 * @Auther: SPL
 * @Date: 2019-07-30 14:32
 * @Description: - 线程死锁
 */
public class DeathThread {

    private String name;
    private int resource;

    public DeathThread(String name, int resource) {
        this.name = name;
        this.resource = resource;
    }

    synchronized void doSome(){
        resource++;
        System.out.println("doing some thing" + resource);
    }
    synchronized void cooperate(DeathThread resource){
        System.out.println("cooperating");
        resource.doSome();
    }


    public static void main(String[] args) {
        DeathThread a = new DeathThread("1",1);
        DeathThread b = new DeathThread("2",2);
        Thread thread1 = new Thread(() -> {
            for(int i = 0; i < 10; i++){
                a.doSome();
                b.cooperate(a);
            }
        });
        System.out.println("t1 over");
        Thread thread2 = new Thread(()->{
            for(int i = 0; i < 10; i++){
                b.doSome();
                a.cooperate(b);
            }
        });
        thread1.start();
        thread2.start();
        System.out.println("t2 over");
    }
}
